package org.jsbd.boss.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IMiguUserAvailableDAO;
import org.jsbd.boss.domian.channel.MiguEffect;
import org.springframework.stereotype.Repository;

@Repository("MiguUserAvailableDao")
public class MiguUserAvailableDAOImpl extends CrackUserBaseDao implements IMiguUserAvailableDAO {

	@Override
	public Map<String, Object> selectMiguUserAvailable(DataGridModel page, MiguEffect musVO) {
		Integer base = musVO.getBase();
		
	    Map<String, Object> results = new HashMap<String, Object>();
	    List<MiguEffect> list = new ArrayList<MiguEffect>(); 
	    if ((base == null || base == 0)) {
	    	List<String> tables = super.queryForList("qy_migu_effect.SELECT_MIGU_EFFECT_TABLES");
	    	for (String table : tables) {
	    		if(table.contains("copy")) {
	    			continue;
	    		}
	    		String[] tableArr = table.split("_");
	    		Integer b = Integer.valueOf(tableArr[3]);
	    		musVO.setBase(b);
	    		musVO.setTable(table);
	    		list.addAll(super.queryForList("qy_migu_effect.SELECT_MIGU_USER_AVAILABLE_LIST", musVO));
	    	}
	    } else {
	    	String table = "qy_migu_effect2_"+base;
	    	musVO.setTable(table);
	    	list = super.queryForList("qy_migu_effect.SELECT_MIGU_USER_AVAILABLE_LIST", musVO);
	    }
	   
	    results.put("rows", list);
	    results.put("total", list.size());
	    return results;
	}

}
